package com.efeichong.project.domain.entity.db;


import com.efeichong.common.domain.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;


/**
 * @author
 * @date 2020/11/25
 * @description 权限
 */
@Setter
@Getter
@Entity
@Table(indexes = {
        @Index(name = "PRIMARY", columnList = "id", unique = true),
        @Index(name = "FKgeupubdqncc1lpgf2cn4fqwbc", columnList = "parent_id"),
})
@DynamicInsert
@DynamicUpdate
public class SysMenu extends BaseEntity {
    /**
     * 父级
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "[parent_id]")
    private SysMenu parent;

    /**
     * 组件
     */
    @Column(name = "[component]", columnDefinition = "varchar(255) default'Layout' comment'组件'")
    private String component;

    /**
     * 图标
     */
    @Column(name = "[icon]", columnDefinition = "varchar(255) comment'图标'")
    private String icon;

    /**
     * 是否为外链（0是 1否）
     */
    @Column(name = "[is_frame]", columnDefinition = "varchar(255) default'0' comment'是否为外链（0是 1否）'")
    private String isFrame;

    /**
     * 类型（M目录 C菜单 F按钮）
     */
    @Column(name = "[menu_type]", columnDefinition = "varchar(255) comment'类型（M目录 C菜单 F按钮）'")
    private String menuType;

    /**
     * 菜单名
     */
    @Column(name = "[name]", columnDefinition = "varchar(255) comment'菜单名'")
    private String name;

    /**
     * 路由地址
     */
    @Column(name = "[path]", columnDefinition = "varchar(255) comment'路由地址'")
    private String path;

    /**
     * 权限字符串
     */
    @Column(name = "[perms]", columnDefinition = "varchar(255) comment'权限字符串'")
    private String perms;

    /**
     * 显示状态（0隐藏 1显示）
     */
    @Column(name = "[visible]", columnDefinition = "int default'1' comment'显示状态（0隐藏 1显示）'")
    private Integer visible;

    /**
     * 排序
     */
    @Column(name = "[order_num]", columnDefinition = "int comment'排序'")
    private Integer orderNum;

    /**
     * 角色
     */
    @ManyToMany(fetch = FetchType.LAZY, mappedBy = "sysMenus")
    private List<SysRole> sysRoles = new ArrayList();

    /**
     * 菜单下级
     */
    @OrderBy("orderNum ASC")
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "parent", cascade = CascadeType.ALL)
    private List<SysMenu> children = new ArrayList();

    /**
     * 是否为叶子 0否 1是
     */
    @Column(name = "[leaves]", columnDefinition = "int default'0' comment'是否为叶子 0否 1是'")
    private Integer leaves;
}
